package Threads.Patterns.Singleton;


//DCL 双检锁
public class Singleton_dcl {
    private Singleton_dcl(){};

    private static volatile Singleton_dcl singleton_dcl=null;//volatile禁止指令重排序

    public static Singleton_dcl getInstance(){
        if (singleton_dcl==null){
            synchronized (Singleton_dcl.class){
                if (singleton_dcl==null){
                    singleton_dcl=new Singleton_dcl();
                }
            }
        }
        return singleton_dcl;
    }
}
